package org.seedltd.upms.service.impl.detection;

import org.seedltd.core.base.BasePage;
import org.seedltd.core.base.BaseServiceImpl;
import org.seedltd.core.utils.Assert;
import org.seedltd.upms.mapper.detection.DetectionCheckTemplateMapper;
import org.seedltd.upms.model.detection.entity.DetectionCheckTemplate;
import org.seedltd.upms.model.detection.form.DetectionCheckTemplateForm;
import org.seedltd.upms.model.detection.form.DetectionCheckTemplateSearchForm;
import org.seedltd.upms.model.detection.vo.DetectionCheckTemplateVO;
import org.seedltd.upms.service.detection.DetectionCheckTemplateService;
import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;

/**
 * 检测结果模板业务实现
 * 
 * @author laizuan
 * @since 2021/08/30
 */
@Service
@AllArgsConstructor
public class DetectionCheckTemplateServiceImpl extends
    BaseServiceImpl<DetectionCheckTemplateMapper, DetectionCheckTemplate> implements DetectionCheckTemplateService {

    @Override
    public DetectionCheckTemplateVO findById(Long id) {
        return q().selectById(id, DetectionCheckTemplateVO.class);
    }

    @Override
    public boolean checkExists(String content) {
        return q().eq(DetectionCheckTemplate::getContent, content).checkExists();
    }

    @Override
    public Long add(DetectionCheckTemplateForm form) {
        Assert.isFalse(this.checkExists(form.getContent()), "已存在重复的模板内容");
        return u().save(form, new DetectionCheckTemplate()).getId();
    }

    @Override
    public boolean update(DetectionCheckTemplateForm form) {
        return u().updateById(form, form.getId());
    }

    @Override
    public boolean delete(Long id) {
        return u().deleteById(id);
    }

    @Override
    public BasePage<DetectionCheckTemplateVO> page(DetectionCheckTemplateSearchForm searchForm) {
        return q(searchForm).selectPage(searchForm.getStart(), searchForm.getSize(), DetectionCheckTemplateVO.class);
    }
}